package com.bdqn.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.base.R;
import com.bdqn.base.logger.WebLogger;
import com.bdqn.pojo.ShopUserLevel;
import com.bdqn.service.ShopUserLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户级别
 *
 * @author lilibo
 * @date 2021/10/05
 */
@Api(tags="用户级别接口")
@RestController
@RequestMapping("/shopuserlevel")
public class ShopUserLevelController {

    @Autowired
    private ShopUserLevelService shopUserLevelService;

    /**
     * 新增用户级别记录
     *
     * @param shopUserLevel
     * @return R
     */
    @ApiOperation("新增用户级别记录")
    @WebLogger("新增用户级别记录")
    @PostMapping("/add")
    public R save(@ApiParam("用户级别对象") @RequestBody ShopUserLevel shopUserLevel) {
        return new R<>(shopUserLevelService.save(shopUserLevel));
    }

    /**
     * 修改用户级别记录
     *
     * @param shopUserLevel
     * @return R
     */
    @ApiOperation("修改用户级别记录")
    @WebLogger("修改用户级别记录")
    @PostMapping("/update")
    public R update(@ApiParam("用户级别对象") @RequestBody ShopUserLevel shopUserLevel) {
        return new R<>(shopUserLevelService.updateById(shopUserLevel));
    }

    /**
     * 通过id删除一条用户级别记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id删除一条用户级别记录")
    @WebLogger("通过id删除一条用户级别记录")
    @PostMapping("/delete")
    public R removeById(@ApiParam("用户级别id") Integer id) {
        return new R<>(shopUserLevelService.removeById(id));
    }

    /**
     * 通过id查询单条用户级别记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id查询单条用户级别记录")
    @WebLogger("通过id查询单条用户级别记录")
    @GetMapping("/{id}")
    public R<ShopUserLevel> getById(@ApiParam("用户级别id") @PathVariable Integer id) {
        return new R<>(shopUserLevelService.getById(id));
    }

    /**
     * 通过用户级别信息查询用户级别记录
     *
     * @param shopUserLevel 用户级别信息对象
     * @return R
     */
    @ApiOperation("通过用户级别信息查询用户级别记录")
    @WebLogger("通过用户级别信息查询用户级别记录")
    @GetMapping("/list")
    public R<List<ShopUserLevel>> getList(@ApiParam("查询的用户级别对象") ShopUserLevel shopUserLevel) {
        return new R<>(shopUserLevelService.getList(shopUserLevel));
    }

    /**
     * 分页查询用户级别
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopUserLevel 用户级别
     * @return
     */
    @ApiOperation("分页查询用户级别")
    @WebLogger("分页查询用户级别")
    @GetMapping("/page")
    public R<IPage<ShopUserLevel>> getPage(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的用户级别对象") ShopUserLevel shopUserLevel) {
        return new R<>(shopUserLevelService.getPage(new Page<>(pageNo, pageSize), shopUserLevel));
    }

    /**
     * 分页查询用户级别数据
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopUserLevel 用户级别
     * @return 返回对象中的count为数据总量
     */
    @ApiOperation("分页查询用户级别数据")
    @WebLogger("分页查询用户级别数据")
    @GetMapping("/pagelist")
    public R<List<ShopUserLevel>> getPageList(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的用户级别对象") ShopUserLevel shopUserLevel) {
        IPage<ShopUserLevel> page = shopUserLevelService.getPage(new Page<>(pageNo, pageSize), shopUserLevel);
        return new R<>(page.getRecords(), page.getTotal());
    }

}
